<template>
	<div>
		<el-card shadow="hover" header="录入">
			<el-button @click="read" size="default" class="mt15" type="primary">
				<SvgIcon name="iconfont icon-step" />读取
			</el-button>
			<el-button @click="write" size="default" class="mt15" type="primary">
				<SvgIcon name="iconfont icon-step" />更新
			</el-button>
			<el-progress :percentage="percent" status="warning" />
			<el-input v-model="input" placeholder="请输入" clearable />
		</el-card>
		<el-card shadow="hover" header="内容">
			<div ref="printRef">
				<div id="report"></div>
			</div>
			<div id="print"></div>
		</el-card>
	</div>
</template>
<script lang="ts">
import { toRefs, reactive, defineComponent } from 'vue'
import post from '/@/utils/post'
export default defineComponent({
	name: 'kaoshi',
	setup() {
		const state = reactive({
			tableData: [],
			date: null,
			input: null,
			percent: 0,
		})
		const format = (percentage) => (percentage === 100 ? 'Full' : `${percentage}%`)

		const read = () => {
			document.getElementById('report').innerHTML = state.input
		}
		const write = async () => {
			if(document.getElementsByClassName('ques-list').length == 1){
				//单选
				for (let i = 1;i<=1;i++){
					let ques = document.getElementById('HrefdivTime'+i)
					let htmlList = ques.getElementsByClassName('col-18 col-offset-2 font-size-16')[0].children
					for (const htm1 in htmlList){
						if(Number(htm1) != 0 && Number(htm1) != 1 && Number(htm1) != 2 && Number(htm1) != 3){
							continue
						}
						
						htmlList[htm1].className = htmlList[htm1].className + ' active'
					}
					console.log(document.getElementById('report').outerHTML)
					break
					setTimeout(async ()=>{
						let ques = document.getElementById('HrefdivTime'+i)
						let selectList = ques.getElementsByClassName('upper-latin-list pl25 mt20')[0].children
						let daan = ''
						for (const one in selectList){
							if(Number(one) != 0 && Number(one) != 1 && Number(one) != 2 && Number(one) != 3){
								continue
							}
							let selectText = selectList[one].getElementsByClassName('text-normal')[0].textContent
							let result = await post.postList({"token": "18f3e68f-701b-4da5-9876-5b58fa0c0d95","lei_xing": "单选","info": selectText},"http://116.205.170.249:8090/adminApi/service/kao/ti")
							if(result.data.总计 != 1){
								break
							}
							if(daan != '' && result.data['答案'] != daan){
								break
							} else {
								daan = result.data['答案']
							}
							if (one == '3'){

							}
						}
						state.percent = i*2
					},1000*Number(i)+1000)
				}
				return
			} else {
				//多选
				return
			}
			alert('既非单选也非多选，请检查元素')
			// let a = await post.postList({"token": "18f3e68f-701b-4da5-9876-5b58fa0c0d95","lei_xing": "单选","info": "myBO"},"http://116.205.170.249:8090/adminApi/service/kao/ti")
			// console.log(a.data)
		}
		return {
			format,
			read,
			write,
			...toRefs(state),
		};
	}
});
</script>
<style scoped>
.demo-progress .el-progress--line {
  margin-bottom: 15px;
  width: 350px;
}
</style>